<?php

//异步加载关键字 配合 autoload
class AjaxKeywordController extends EController
{
	//过滤器
	public function filters()
	{
		return array(
			array(
				'application.filters.BackEndAuthRequestFilter -getkeyword -gettag',
			)
		);
	}
	
	public function actiongetkeyword()
	{  
		$a = isset($_GET["a"])?trim($_GET["a"]):"keyword";
		$key = isset($_GET["term"])?trim($_GET["term"]):"";
		$type = isset($_GET["type"])?trim($_GET["type"]):0;

		/*关键词*/
		if($key && $a=="keyword"){
		    $sql = "select keyword from keywords where keyword like '%".$key."%' order by id desc limit 0,40"; 
		    $rs=Yii::app()->download->createCommand($sql)->queryAll();
			$array = array();
			foreach($rs as $key=>$row){
			   $array[$key]=array("label"=>$row["keyword"],"value"=>$row["keyword"]);
			}
			echo json_encode($array);die;
		}
		die;
	}

	public function actiongettag()
	{
		$key = isset($_GET["t"])?trim($_GET["t"]):"";

		/*关键词*/
		if($key){
		    $sql = "select name from heji where name like '%".$key."%' order by id desc limit 0,40"; 
		    $rs=Yii::app()->download->createCommand($sql)->queryAll();
			$array = array();
			$str = '<ul>';
			foreach($rs as $key=>$row){
			   $str .= '<li>'.$row["name"].'</li>';
			}
			$str .= '</ul>';
			echo $str;die;
		}else{
			echo 0;die;
		}
		die;
	}
}